package primalgorithms.array;

public class _02MaxProfit {
    public static int maxProfit(int[] prices) {
        if(prices == null || prices.length == 0){
            return 0;
        }
        //贪心算法，求上升区间的高度差
        int sum = 0;
        for (int high = 1;high < prices.length;high++){
            //如果左边值小于右边，high++
            if(prices[high-1] <= prices[high]){
                sum += prices[high] - prices[high-1];
            }
        }
        return sum;
    }
}
